package com.adingxiong.cft.service.impl;

import com.adingxiong.cft.database.MongoSysRepository;
import com.adingxiong.cft.entity.MgSysLog;
import com.adingxiong.cft.entity.SysLog;
import com.adingxiong.cft.mapper.SysLogMapper;
import com.adingxiong.cft.service.MgSysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName MgSysServiceImpl
 * @Description TODO
 * @Author xiongchao
 * @Date 2021/1/15 16:54
 **/
@Service
public class MgSysServiceImpl implements MgSysService {

    @Autowired
    private MongoSysRepository repository;


    @Override
    public int create(MgSysLog sysLog) {
        sysLog.setId(null);
        sysLog.setCreateTime(new Date());
        repository.save(sysLog);
        return 1;
    }

    @Override
    public int delete(List<String> ids) {
        List<MgSysLog> list = new ArrayList<>();
        ids.forEach(e -> {
            MgSysLog log = new MgSysLog();
            log.setId(e);
            list.add(log);
        });
        repository.deleteAll(list);
        return 0;
    }

    @Override
    public List<MgSysLog> findByOperation(String op) {
        List<MgSysLog> byOperationOrderByCreateTime = repository.findByOperationOrderByCreateTime(op);
        return byOperationOrderByCreateTime;
    }
}
